//
//  MYInformationViewController.m
//  MiYuan_iOS
//
//  Created by zhangyongbing on 2018/5/15.
//  Copyright © 2018年 zhangyongbing. All rights reserved.
//

#import "MYInformationViewController.h"

@interface MYInformationViewController ()
@property (nonatomic,strong) NSMutableDictionary    *dicPersonal;
@property (nonatomic,weak) IBOutlet       UILabel     *labName;
@property (nonatomic,weak) IBOutlet       UILabel     *labPhone;
@property (nonatomic,weak) IBOutlet       UILabel     *labSccount;
@property (nonatomic,weak) IBOutlet   UIView          *viewHead;
@end

@implementation MYInformationViewController

-(instancetype)initWithInformationDetailDic:(NSDictionary *)dictionary
{
    self = [super initWithNibName:@"MYInformationViewController" bundle:nil];
    if (self) {
        [self.dicPersonal removeAllObjects];
        [self.dicPersonal addEntriesFromDictionary:dictionary];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    NSString *version= [UIDevice currentDevice].systemVersion;
    
    if(version.doubleValue >=11.0) {
        
    }else{
        // 针对 11.0 以下的iOS系统进行处理
        for (NSLayoutConstraint *constraint in self.viewHead.superview.constraints) {
            if (constraint.firstItem == self.viewHead && constraint.firstAttribute == NSLayoutAttributeTop) {
                constraint.constant = 20;
            }
        }
        
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    [self reloadPersonalInformation];
}

- (void)reloadPersonalInformation
{
    NSString *name = [NSString stringWithFormat:@"%@",[self.dicPersonal objectForKey:@"name"]];
    if ([name stringIsValid]) {
        [self.labName setText:name];
    }
    else{
        [self.labName setText:@""];
    }
    
    NSString *jobNumber = [NSString stringWithFormat:@"%@",[self.dicPersonal objectForKey:@"jobNumber"]];
    if ([jobNumber stringIsValid]) {
        [self.labSccount setText:jobNumber];
    }
    else{
        [self.labSccount setText:@""];
    }
    
    NSString *phone = [NSString stringWithFormat:@"%@",[self.dicPersonal objectForKey:@"phone"]];
    if ([phone stringIsValid]) {
        [self.labPhone setText:phone];
    }
    else{
        [self.labPhone setText:@""];
    }
}

- (IBAction)onBackButtonPressed:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (NSMutableDictionary *)dicPersonal
{
    if (_dicPersonal == nil) {
        _dicPersonal = [[NSMutableDictionary alloc] init];
    }
    return _dicPersonal;
}

@end
